package com.perfma.xtest.tool;

import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
import java.io.*;

/**
 * @author: junhui.si
 * @date: 2023-07-11 15:09
 **/
public class Test123 extends HTMLEditorKit.ParserCallback {
    private static Test123 test = new Test123();
    private StringBuffer buff;

    private void parse(String str) throws IOException {
        InputStream iin = new ByteArrayInputStream(str.getBytes());
        Reader in = new InputStreamReader(iin);
        buff = new StringBuffer();
        ParserDelegator delegator = new ParserDelegator();
        delegator.parse(in, this, Boolean.TRUE);
        iin.close();
        in.close();
    }

    @Override
    public void handleText(char[] text, int pos) {
        buff.append(text);
    }

    private String getText() {
        return buff.toString();
    }

    public static String getContent(String str) {
        try {
            test.parse(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return test.getText();
    }
}